package cn.sixmillions.ps.common.handler;

import cn.sixmillions.ps.common.base.R;
import com.qingstor.sdk.exception.QSException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;

/**
 * 基础异常处理类
 *
 * @author sixmillions
 * @since 2021/06/04
 **/
@Slf4j
@RestControllerAdvice
public class BaseExceptionHandler {

    /**
     * 上传青云OSS异常
     */
    @ExceptionHandler(QSException.class)
    public R<Object> qingStorExceptionHandler(Exception ex, HttpServletRequest request) {
        log.error("url:{},| 上传青云OSS异常:{}", request.getRequestURI(), ex.getMessage(), ex);
        return R.fail(ex.getMessage());
    }

    /**
     * 总异常
     */
    @ExceptionHandler(Exception.class)
    public R<Object> exceptionHandler(Exception ex, HttpServletRequest request) {
        log.error("url:{},| errMsg:{}", request.getRequestURI(), ex.getMessage(), ex);
        return R.fail(ex.getMessage());
    }
}
